using System;
using System.Configuration;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.Configuration;
using Xunit;

namespace Unity.Extensions
{
    public class InterceptRemotingConfigurationTest
    {
        [Fact]
        public void InterceptConfiguration()
        {
            Recorder.Records.Clear();
            IUnityContainer container = new UnityContainer();
            UnityConfigurationSection section = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");
            section.Containers.Default.Configure(container);

            SpyMBRO obj = container.Resolve<SpyMBRO>();
            obj.InterceptedMethod();

            Assert.Equal(3, Recorder.Records.Count);
            Assert.Equal("Before Method", Recorder.Records[0]);
            Assert.Equal("In Method", Recorder.Records[1]);
            Assert.Equal("After Method", Recorder.Records[2]);
        }

        internal class SpyMBRO : MarshalByRefObject
        {
            public void InterceptedMethod()
            {
                Recorder.Records.Add("In Method");
            }
        }
    }
}